﻿using System;
using Core;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;

public class MoveAnimConf
{
    private static readonly Dictionary<string, Dictionary<EDir4, SortedList<int, Sprite>>> spriteDict = new();

    //private static readonly string SrcPath = "Assets/Proj/Games/g_pixelfarm/Art/Sprite";
    //private static readonly string TgtPath = "Assets/Proj/Games/g_pixelfarm/Res/ScriptableObject/Animation";

    [MenuItem("Assets/Mini Tools/Texture/移动 Anim Conf", false, 302)]
    private static void Main()
    {
        var index = Application.dataPath.IndexOf("Assets", StringComparison.Ordinal);
        var dataPath = Application.dataPath[..index];

        var assetGUIDs = Selection.assetGUIDs;
        if (assetGUIDs is { Length: > 0 })
        {
            for (var i = 0; i < assetGUIDs.Length; i++)
            {
                var path = AssetDatabase.GUIDToAssetPath(assetGUIDs[i]);

                if (File.Exists(path)) continue;

                var files = Utils.File.GetFiles(path);
                files.RemoveAll(c => !c.EndsWith(".asset") ||
                                     c.IndexOf("Art/Sprite", StringComparison.Ordinal) < 0);

                foreach (var oldPath in files)
                {
                    var newPath = oldPath.Replace("Art/Sprites", "Res/ScriptableObject/Animation");
                    newPath = newPath.Replace("Art/Sprite", "Res/ScriptableObject/Animation");

                    if (Utils.File.CreateDirectoryByFilePath(newPath))
                    {
                        AssetDatabase.Refresh();
                    }

                    var oldPath1 = oldPath.Replace(dataPath, "");
                    var newPath1 = newPath.Replace(dataPath, "");

                    Debug.Log(oldPath1);
                    AssetDatabase.DeleteAsset(newPath1);
                    AssetDatabase.MoveAsset(oldPath1, newPath1);
                }
            }
        }

        AssetDatabase.Refresh(); //刷新
        Debug.Log("处理完成");
    }
}
